from CvPythonExtensions import *
from WriterUtils import *

import CvScreenEnums
import CvUtil
import CvConfigParser
import CvPath
import os
import os.path
import Popup as PyPopup
import shutil 

# globals
gc = CyGlobalContext()
ArtFileMgr = CyArtFileMgr()
localText = CyTranslator()

# Change this to change the location where the resulting CIV4UnitInfos.xml file 
# will be saved. So if the default value is left to "Test" then the 
# CIV4UnitInfos.xml file would be written in a directory called "Test" inside 
# of the Tech Tree Editor mod folder.
# Default value is Test
g_strSaveDirectoryLocation = "Test"

# Change the value to false if the assets directory structure shouldn't be 
# created at the directory specified by the "Save Directory Location".
# Default value is True
g_bCreateAssetHierarchy = True

# Change the value to false if the changes made shouldn't be saved into the 
# assets directory for the tech editor. Changing it to false will require 
# manual copying of the saved files from the directory specified in the 
# "Save Directory Location" configurable option to the editor's asset directory 
# when wanting to edit existing mod files.
# Default value is True
g_bSaveChangesInEditorAssetsDirectory = True

def loadConfigurationValues():
	global g_strSaveDirectoryLocation
	global g_bCreateAssetHierarchy
	global g_bSaveChangesInEditorAssetsDirectory
	
	config = CvConfigParser.CvConfigParser("ViSa_v3.ini")

	if(config != None):
		g_strSaveDirectoryLocation = config.get("Tech Tree Editor", "Save Directory Location", "Test")
		g_bCreateAssetHierarchy = config.getboolean("Tech Tree Editor", "Create Asset Hierarchy", True)
		g_bSaveChangesInEditorAssetsDirectory = config.getboolean("Tech Tree Editor", "Save Changes In Editor Assets Directory", True)

		if(len(g_strSaveDirectoryLocation) == 0):
			g_strSaveDirectoryLocation = "Test"
			
class UnitInfoWriter:
		
	def __init__(self):
		loadConfigurationValues()
				
	def isUnitClassUpgradesDefined(self, iUnit):
		objUnitInfo = gc.getUnitInfo(iUnit)

		for iI in range(gc.getNumUnitClassInfos()):
			if(objUnitInfo.getUpgradeUnitClass(iI)):
				return true
				
		return false
				
	def isUnitClassTargetsDefined(self, iUnit):
		objUnitInfo = gc.getUnitInfo(iUnit)

		for iI in range(gc.getNumUnitClassInfos()):
			if(objUnitInfo.getTargetUnitClass(iI)):
				return true
				
		return false

	def isUnitCombatTargetsDefined(self, iUnit):
		objUnitInfo = gc.getUnitInfo(iUnit)

		for iI in range(gc.getNumUnitCombatInfos()):
			if(objUnitInfo.getTargetUnitCombat(iI) != 0):
				return true
				
		return false
				
	def isUnitClassDefendersDefined(self, iUnit):
		objUnitInfo = gc.getUnitInfo(iUnit)

		for iI in range(gc.getNumUnitClassInfos()):
			if(objUnitInfo.getDefenderUnitClass(iI)):
				return true
				
		return false

	def isUnitCombatDefendersDefined(self, iUnit):
		objUnitInfo = gc.getUnitInfo(iUnit)

		for iI in range(gc.getNumUnitCombatInfos()):
			if(objUnitInfo.getDefenderUnitCombat(iI) != 0):
				return true
				
		return false

	def isUnitAIDefined(self, iUnit):
		objUnitInfo = gc.getUnitInfo(iUnit)

		for iI in range(UnitAITypes.NUM_UNITAI_TYPES):
			if(objUnitInfo.getUnitAIType(iI)):
				return true
				
		return false

	def isNotUnitAIDefined(self, iUnit):
		objUnitInfo = gc.getUnitInfo(iUnit)

		for iI in range(UnitAITypes.NUM_UNITAI_TYPES):
			if(objUnitInfo.getNotUnitAIType(iI)):
				return true
				
		return false
				
	def isBuildsDefined(self, iUnit):
		objUnitInfo = gc.getUnitInfo(iUnit)

		for iI in range(gc.getNumBuildInfos()):
			if(objUnitInfo.getBuilds(iI)):
				return true
				
		return false
				
	def isReligionSpreadsDefined(self, iUnit):
		objUnitInfo = gc.getUnitInfo(iUnit)

		for iI in range(gc.getNumReligionInfos()):
			if(objUnitInfo.getReligionSpreads(iI)):
				return true
				
		return false
				
	def isGreatPeoplesDefined(self, iUnit):
		objUnitInfo = gc.getUnitInfo(iUnit)

		for iI in range(gc.getNumSpecialistInfos()):
			if(objUnitInfo.getGreatPeoples(iI)):
				return true
				
		return false
				
	def isBuildingsDefined(self, iUnit):
		objUnitInfo = gc.getUnitInfo(iUnit)

		for iI in range(gc.getNumBuildingInfos()):
			if(objUnitInfo.getBuildings(iI)):
				return true
				
		return false
		
	def isForceBuildingsDefined(self, iUnit):
		objUnitInfo = gc.getUnitInfo(iUnit)

		for iI in range(gc.getNumBuildingInfos()):
			if(objUnitInfo.getForceBuildings(iI)):
				return true
				
		return false

	def isPrereqAndTechsDefined(self, iUnit):
		objUnitInfo = gc.getUnitInfo(iUnit)

		for iI in range (gc.getDefineINT("NUM_UNIT_AND_TECH_PREREQS")):
			if(objUnitInfo.getPrereqAndTechs(iI) != TechTypes.NO_TECH):
				return true			
		return false

	def isPrereqOrBonusesDefined(self, iUnit):
		objUnitInfo = gc.getUnitInfo(iUnit)

		for iI in range (gc.getDefineINT("NUM_UNIT_PREREQ_OR_BONUSES")):
			if(objUnitInfo.getPrereqOrBonuses(iI) != BonusTypes.NO_BONUS):
				return true			
		return false

	def isProductionTraitDefined(self, iUnit):
		objUnitInfo = gc.getUnitInfo(iUnit)

		for iI in range (gc.getNumTraitInfos()):
			if(objUnitInfo.getProductionTraits(iI) != 0):
				return true				
		return false	

	def isFlavorsDefined(self, iUnit):
		objUnitInfo = gc.getUnitInfo(iUnit)

		for iI in range(gc.getNumFlavorTypes()):
			if(objUnitInfo.getFlavorValue(iI) != 0):
				return true	
		return false
				
	def isTerrainImpassablesDefined(self, iUnit):
		objUnitInfo = gc.getUnitInfo(iUnit)

		for iI in range(gc.getNumTerrainInfos()):
			if(objUnitInfo.getTerrainImpassable(iI)):
				return true
				
		return false
				
	def isFeatureImpassablesDefined(self, iUnit):
		objUnitInfo = gc.getUnitInfo(iUnit)

		for iI in range(gc.getNumFeatureInfos()):
			if(objUnitInfo.getFeatureImpassable(iI)):
				return true
				
		return false
				
	def isTerrainNativesDefined(self, iUnit):
		objUnitInfo = gc.getUnitInfo(iUnit)

		for iI in range(gc.getNumTerrainInfos()):
			if(objUnitInfo.getTerrainNative(iI)):
				return true
				
		return false
				
	def isFeatureNativesDefined(self, iUnit):
		objUnitInfo = gc.getUnitInfo(iUnit)

		for iI in range(gc.getNumFeatureInfos()):
			if(objUnitInfo.getFeatureNative(iI)):
				return true
				
		return false
				
	def isTerrainDefensesDefined(self, iUnit):
		objUnitInfo = gc.getUnitInfo(iUnit)

		for iI in range(gc.getNumTerrainInfos()):
			if(objUnitInfo.getTerrainDefenseModifier(iI) != 0):
				return true
				
		return false
				
	def isFeatureDefensesDefined(self, iUnit):
		objUnitInfo = gc.getUnitInfo(iUnit)

		for iI in range(gc.getNumFeatureInfos()):
			if(objUnitInfo.getFeatureDefenseModifier(iI) != 0):
				return true
				
		return false
				
	def isUnitClassAttackModifiersDefined(self, iUnit):
		objUnitInfo = gc.getUnitInfo(iUnit)

		for iI in range(gc.getNumUnitClassInfos()):
			if(objUnitInfo.getUnitClassAttackModifier(iI) != 0):
				return true
				
		return false
		
	def isUnitClassDefenseModifiersDefined(self, iUnit):
		objUnitInfo = gc.getUnitInfo(iUnit)

		for iI in range(gc.getNumUnitClassInfos()):
			if(objUnitInfo.getUnitClassDefenseModifier(iI) != 0):
				return true
				
		return false

	def isUnitCombatModifiersDefined(self, iUnit):
		objUnitInfo = gc.getUnitInfo(iUnit)

		for iI in range(gc.getNumUnitCombatInfos()):
			if(objUnitInfo.getUnitCombatModifier(iI) != 0):
				return true
				
		return false

	def isUnitCombatCollateralImmunesDefined(self, iUnit):
		objUnitInfo = gc.getUnitInfo(iUnit)

		for iI in range(gc.getNumUnitCombatInfos()):
			if(objUnitInfo.getUnitCombatCollateralImmune(iI) != 0):
				return true
				
		return false

	def isDomainModifiersDefined(self, iUnit):
		objUnitInfo = gc.getUnitInfo(iUnit)

		for iI in range(DomainTypes.NUM_DOMAIN_TYPES):
			if(objUnitInfo.getDomainModifier(iI) != 0):
				return true
				
		return false
						
	def isBonusProductionModifiersDefined(self, iUnit):
		objUnitInfo = gc.getUnitInfo(iUnit)

		for iI in range(gc.getNumBonusInfos()):
			if(objUnitInfo.getBonusProductionModifier(iI) != 0):
				return true	
		return false
		
	def isFreePromotionsDefined(self, iUnit):
		objUnitInfo = gc.getUnitInfo(iUnit)

		for iI in range(gc.getNumPromotionInfos()):
			if(objUnitInfo.getFreePromotions(iI)):
				return true
				
		return false

	def printUnit(self, iUnit):
		objUnitInfo = gc.getUnitInfo(iUnit)

		szText = ""
		
		szText = appendString(szText,"		<UnitInfo>")
		
		szText = appendString(szText,"			<Class>%s</Class>" %(gc.getUnitClassInfo(objUnitInfo.getUnitClassType()).getType()))		
		szText = appendString(szText,"			<Type>%s</Type>" %(objUnitInfo.getType()))

		if(objUnitInfo.getNumUnitNames() > 0):
			szText = appendString(szText,"			<UniqueNames>")
			for iI in range(objUnitInfo.getNumUnitNames()):
				szText = appendString(szText,"				<UniqueName>%s</UniqueName>" %(objUnitInfo.getUnitNames(iI)))
			szText = appendString(szText,"			</UniqueNames>")
		else:
			szText = appendString(szText,"			<UniqueNames/>")

		if(objUnitInfo.getSpecialUnitType() != -1):
			szText = appendString(szText,"			<Special>%s</Special>" %(gc.getSpecialUnitInfo(objUnitInfo.getSpecialUnitType()).getType()))
		else:
			szText = appendString(szText,"			<Special>NONE</Special>")

		if(objUnitInfo.getUnitCaptureClassType() != -1):
			szText = appendString(szText,"			<Capture>%s</Capture>" %(gc.getUnitClassInfo(objUnitInfo.getUnitCaptureClassType()).getType()))
		else:
			szText = appendString(szText,"			<Capture>NONE</Capture>")

		if(objUnitInfo.getUnitCombatType() != -1):
			szText = appendString(szText,"			<Combat>%s</Combat>" %(gc.getUnitCombatInfo(objUnitInfo.getUnitCombatType()).getType()))
		else:
			szText = appendString(szText,"			<Combat>NONE</Combat>")

		if(objUnitInfo.getDomainType() != -1):
			szText = appendString(szText,"			<Domain>%s</Domain>" %(gc.getDomainInfo(objUnitInfo.getDomainType()).getType()))
		else:
			szText = appendString(szText,"			<Domain>NONE</Domain>")

		if(objUnitInfo.getDefaultUnitAIType() != -1):
			szText = appendString(szText,"			<DefaultUnitAI>%s</DefaultUnitAI>" %(gc.getUnitAIInfo(objUnitInfo.getDefaultUnitAIType()).getType()))
		else:
			szText = appendString(szText,"			<DefaultUnitAI>NONE</DefaultUnitAI>")

		if(objUnitInfo.getInvisibleType() != -1):
			szText = appendString(szText,"			<Invisible>%s</Invisible>" %(gc.getInvisibleInfo(objUnitInfo.getInvisibleType()).getType()))
		else:
			szText = appendString(szText,"			<Invisible>NONE</Invisible>")

		if(objUnitInfo.getSeeInvisibleType() != -1):
			szText = appendString(szText,"			<SeeInvisible>%s</SeeInvisible>" %(gc.getInvisibleInfo(objUnitInfo.getSeeInvisibleType()).getType()))
		else:
			szText = appendString(szText,"			<SeeInvisible>NONE</SeeInvisible>")


		szText = appendString(szText,"			<Description>%s</Description>" %(objUnitInfo.getTextKey()))
		szText = appendString(szText,"			<Civilopedia>%s</Civilopedia>" %(objUnitInfo.getCivilopediaKey()))
		szText = appendString(szText,"			<Strategy>%s</Strategy>" %(objUnitInfo.getStrategyKey()))
			
		if(objUnitInfo.getAdvisorType() != -1):
			szText = appendString(szText,"			<Advisor>%s</Advisor>" %(gc.getAdvisorInfo(objUnitInfo.getAdvisorType()).getType()))
		else:
			szText = appendString(szText,"			<Advisor>NONE</Advisor>")

		szText = appendString(szText,"			<bAnimal>%s</bAnimal>" %(boolToInt(objUnitInfo.isAnimal())))
		szText = appendString(szText,"			<bFood>%s</bFood>" %(boolToInt(objUnitInfo.isFoodProduction())))
		szText = appendString(szText,"			<bNoBadGoodies>%s</bNoBadGoodies>" %(boolToInt(objUnitInfo.isNoBadGoodies())))
		szText = appendString(szText,"			<bOnlyDefensive>%s</bOnlyDefensive>" %(boolToInt(objUnitInfo.isOnlyDefensive())))
		szText = appendString(szText,"			<bNoCapture>%s</bNoCapture>" %(boolToInt(objUnitInfo.isNoCapture())))
		szText = appendString(szText,"			<bRivalTerritory>%s</bRivalTerritory>" %(boolToInt(objUnitInfo.isRivalTerritory())))
		szText = appendString(szText,"			<bMilitaryHappiness>%s</bMilitaryHappiness>" %(boolToInt(objUnitInfo.isMilitaryHappiness())))
		szText = appendString(szText,"			<bMilitarySupport>%s</bMilitarySupport>" %(boolToInt(objUnitInfo.isMilitarySupport())))
		szText = appendString(szText,"			<bMilitaryProduction>%s</bMilitaryProduction>" %(boolToInt(objUnitInfo.isMilitaryProduction())))
		szText = appendString(szText,"			<bPillage>%s</bPillage>" %(boolToInt(objUnitInfo.isPillage())))
		szText = appendString(szText,"			<bSabotage>%s</bSabotage>" %(boolToInt(objUnitInfo.isSabotage())))
		szText = appendString(szText,"			<bDestroy>%s</bDestroy>" %(boolToInt(objUnitInfo.isDestroy())))
		szText = appendString(szText,"			<bStealPlans>%s</bStealPlans>" %(boolToInt(objUnitInfo.isStealPlans())))
		szText = appendString(szText,"			<bInvestigate>%s</bInvestigate>" %(boolToInt(objUnitInfo.isInvestigate())))
		szText = appendString(szText,"			<bCounterSpy>%s</bCounterSpy>" %(boolToInt(objUnitInfo.isCounterSpy())))
		szText = appendString(szText,"			<bFound>%s</bFound>" %(boolToInt(objUnitInfo.isFound())))
		szText = appendString(szText,"			<bGoldenAge>%s</bGoldenAge>" %(boolToInt(objUnitInfo.isGoldenAge())))
		szText = appendString(szText,"			<bInvisible>%s</bInvisible>" %(boolToInt(objUnitInfo.isInvisible())))
		szText = appendString(szText,"			<bFirstStrikeImmune>%s</bFirstStrikeImmune>" %(boolToInt(objUnitInfo.isFirstStrikeImmune())))
		szText = appendString(szText,"			<bNoDefensiveBonus>%s</bNoDefensiveBonus>" %(boolToInt(objUnitInfo.isNoDefensiveBonus())))
		szText = appendString(szText,"			<bIgnoreBuildingDefense>%s</bIgnoreBuildingDefense>" %(boolToInt(objUnitInfo.isIgnoreBuildingDefense())))
		szText = appendString(szText,"			<bCanMoveImpassable>%s</bCanMoveImpassable>" %(boolToInt(objUnitInfo.isCanMoveImpassable())))
		szText = appendString(szText,"			<bFlatMovementCost>%s</bFlatMovementCost>" %(boolToInt(objUnitInfo.isFlatMovementCost())))
		szText = appendString(szText,"			<bIgnoreTerrainCost>%s</bIgnoreTerrainCost>" %(boolToInt(objUnitInfo.isIgnoreTerrainCost())))
		szText = appendString(szText,"			<bNukeImmune>%s</bNukeImmune>" %(boolToInt(objUnitInfo.isNukeImmune())))
		szText = appendString(szText,"			<bPrereqBonuses>%s</bPrereqBonuses>" %(boolToInt(objUnitInfo.isPrereqBonuses())))
		szText = appendString(szText,"			<bPrereqReligion>%s</bPrereqReligion>" %(boolToInt(objUnitInfo.isPrereqReligion())))
		szText = appendString(szText,"			<bMechanized>%s</bMechanized>" %(boolToInt(objUnitInfo.isMechUnit())))

		if(objUnitInfo.isRenderBelowWater()):
			szText = appendString(szText,"			<bRenderBelowWater>%s</bRenderBelowWater>" %(boolToInt(objUnitInfo.isRenderBelowWater())))

		if(self.isUnitClassUpgradesDefined(iUnit)):
			szText = appendString(szText,"			<UnitClassUpgrades>")
			for iI in range(gc.getNumUnitClassInfos()):
				if(objUnitInfo.getUpgradeUnitClass(iI)):
					szText = appendString(szText,"				<UnitClassUpgrade>")
					szText = appendString(szText,"					<UnitClassUpgradeType>%s</UnitClassUpgradeType>" %(gc.getUnitClassInfo(iI).getType()))
					szText = appendString(szText,"					<bUnitClassUpgrade>1</bUnitClassUpgrade>")
					szText = appendString(szText,"				</UnitClassUpgrade>")
				
			szText = appendString(szText,"			</UnitClassUpgrades>")
		else:
			szText = appendString(szText,"			<UnitClassUpgrades/>")

		if(self.isUnitClassTargetsDefined(iUnit)):
			szText = appendString(szText,"			<UnitClassTargets>")
			for iI in range(gc.getNumUnitClassInfos()):
				if(objUnitInfo.getTargetUnitClass(iI)):
					szText = appendString(szText,"				<UnitClassTarget>")
					szText = appendString(szText,"					<UnitClassTargetType>%s</UnitClassTargetType>" %(gc.getUnitClassInfo(iI).getType()))
					szText = appendString(szText,"					<bUnitClassTarget>1</bUnitClassTarget>")
					szText = appendString(szText,"				</UnitClassTarget>")
				
			szText = appendString(szText,"			</UnitClassTargets>")
		else:
			szText = appendString(szText,"			<UnitClassTargets/>")
		
		if(self.isUnitCombatTargetsDefined(iUnit)):
			szText = appendString(szText,"			<UnitCombatTargets>")
			for iI in range(gc.getNumUnitCombatInfos()):
				if(objUnitInfo.getTargetUnitCombat(iI)):
					szText = appendString(szText,"				<UnitCombatTarget>")
					szText = appendString(szText,"					<UnitCombatTargetType>%s</UnitCombatTargetType>" %(gc.getUnitCombatInfo(iI).getType()))
					szText = appendString(szText,"					<bUnitCombatTarget>1</bUnitCombatTarget>")
					szText = appendString(szText,"				</UnitCombatTarget>")
				
			szText = appendString(szText,"			</UnitCombatTargets>")
		else:
			szText = appendString(szText,"			<UnitCombatTargets/>")

		if(self.isUnitClassDefendersDefined(iUnit)):
			szText = appendString(szText,"			<UnitClassDefenders>")
			for iI in range(gc.getNumUnitClassInfos()):
				if(objUnitInfo.getDefenderUnitClass(iI)):
					szText = appendString(szText,"				<UnitClassDefender>")
					szText = appendString(szText,"					<UnitClassDefenderType>%s</UnitClassDefenderType>" %(gc.getUnitClassInfo(iI).getType()))
					szText = appendString(szText,"					<bUnitClassDefender>1</bUnitClassDefender>")
					szText = appendString(szText,"				</UnitClassDefender>")
				
			szText = appendString(szText,"			</UnitClassDefenders>")
		else:
			szText = appendString(szText,"			<UnitClassDefenders/>")
		
		if(self.isUnitCombatDefendersDefined(iUnit)):
			szText = appendString(szText,"			<UnitCombatDefenders>")
			for iI in range(gc.getNumUnitCombatInfos()):
				if(objUnitInfo.getDefenderUnitCombat(iI)):
					szText = appendString(szText,"				<UnitCombatDefender>")
					szText = appendString(szText,"					<UnitCombatDefenderType>%s</UnitCombatDefenderType>" %(gc.getUnitCombatInfo(iI).getType()))
					szText = appendString(szText,"					<bUnitCombatDefender>1</bUnitCombatDefender>")
					szText = appendString(szText,"				</UnitCombatDefender>")
				
			szText = appendString(szText,"			</UnitCombatDefenders>")
		else:
			szText = appendString(szText,"			<UnitCombatDefenders/>")

		if(self.isUnitAIDefined(iUnit)):
			szText = appendString(szText,"			<UnitAIs>")
			for iI in range(UnitAITypes.NUM_UNITAI_TYPES):
				if(objUnitInfo.getUnitAIType(iI)):
					szText = appendString(szText,"				<UnitAI>")
					szText = appendString(szText,"					<UnitAIType>%s</UnitAIType>" %(gc.getUnitAIInfo(iI).getType()))
					szText = appendString(szText,"					<bUnitAI>1</bUnitAI>")
					szText = appendString(szText,"				</UnitAI>")
				
			szText = appendString(szText,"			</UnitAIs>")
		else:
			szText = appendString(szText,"			<UnitAIs/>")

		if(self.isNotUnitAIDefined(iUnit)):
			szText = appendString(szText,"			<NotUnitAIs>")
			for iI in range(UnitAITypes.NUM_UNITAI_TYPES):
				if(objUnitInfo.getNotUnitAIType(iI)):
					szText = appendString(szText,"				<UnitAI>")
					szText = appendString(szText,"					<UnitAIType>%s</UnitAIType>" %(gc.getUnitAIInfo(iI).getType()))
					szText = appendString(szText,"					<bUnitAI>1</bUnitAI>")
					szText = appendString(szText,"				</UnitAI>")
				
			szText = appendString(szText,"			</NotUnitAIs>")
		else:
			szText = appendString(szText,"			<NotUnitAIs/>")

		if(self.isBuildsDefined(iUnit)):
			szText = appendString(szText,"			<Builds>")
			for iI in range(gc.getNumBuildInfos()):
				if(objUnitInfo.getBuilds(iI)):
					szText = appendString(szText,"				<Build>")
					szText = appendString(szText,"					<BuildType>%s</BuildType>" %(gc.getBuildInfo(iI).getType()))
					szText = appendString(szText,"					<bBuild>1</bBuild>")
					szText = appendString(szText,"				</Build>")
				
			szText = appendString(szText,"			</Builds>")
		else:
			szText = appendString(szText,"			<Builds/>")

		if(self.isReligionSpreadsDefined(iUnit)):
			szText = appendString(szText,"			<ReligionSpreads>")
			for iI in range(gc.getNumReligionInfos()):
				if(objUnitInfo.getReligionSpreads(iI)):
					szText = appendString(szText,"				<ReligionSpread>")
					szText = appendString(szText,"					<ReligionType>%s</ReligionType>" %(gc.getReligionInfo(iI).getType()))
					szText = appendString(szText,"					<bReligionSpread>1</bReligionSpread>")
					szText = appendString(szText,"				</ReligionSpread>")
				
			szText = appendString(szText,"			</ReligionSpreads>")
		else:
			szText = appendString(szText,"			<ReligionSpreads/>")

		if(self.isGreatPeoplesDefined(iUnit)):
			szText = appendString(szText,"			<GreatPeoples>")
			for iI in range(gc.getNumSpecialistInfos()):
				if(objUnitInfo.getGreatPeoples(iI)):
					szText = appendString(szText,"				<GreatPeople>")
					szText = appendString(szText,"					<GreatPeopleType>%s</GreatPeopleType>" %(gc.getSpecialistInfo(iI).getType()))
					szText = appendString(szText,"					<bGreatPeople>1</bGreatPeople>")
					szText = appendString(szText,"				</GreatPeople>")
				
			szText = appendString(szText,"			</GreatPeoples>")
		else:
			szText = appendString(szText,"			<GreatPeoples/>")
			
		if(self.isBuildingsDefined(iUnit)):
			szText = appendString(szText,"			<Buildings>")
			for iI in range(gc.getNumBuildingInfos()):
				if(objUnitInfo.getBuildings(iI)):
					szText = appendString(szText,"				<Building>")
					szText = appendString(szText,"					<BuildingType>%s</BuildingType>" %(gc.getBuildingInfo(iI).getType()))
					szText = appendString(szText,"					<bBuilding>1</bBuilding>")
					szText = appendString(szText,"				</Building>")
				
			szText = appendString(szText,"			</Buildings>")
		else:
			szText = appendString(szText,"			<Buildings/>")

		if(self.isForceBuildingsDefined(iUnit)):
			szText = appendString(szText,"			<ForceBuildings>")
			for iI in range(gc.getNumBuildingInfos()):
				if(objUnitInfo.getForceBuildings(iI)):
					szText = appendString(szText,"				<ForceBuilding>")
					szText = appendString(szText,"					<BuildingType>%s</BuildingType>" %(gc.getBuildingInfo(iI).getType()))
					szText = appendString(szText,"					<bForceBuilding>1</bForceBuilding>")
					szText = appendString(szText,"				</ForceBuilding>")
				
			szText = appendString(szText,"			</ForceBuildings>")
		else:
			szText = appendString(szText,"			<ForceBuildings/>")

		if(objUnitInfo.getHolyCity() != -1):
			szText = appendString(szText,"			<HolyCity>%s</HolyCity>" %(gc.getReligionInfo(objUnitInfo.getHolyCity()).getType()))
		else:
			szText = appendString(szText,"			<HolyCity>NONE</HolyCity>")

		if(objUnitInfo.getReligionType() != -1):
			szText = appendString(szText,"			<ReligionType>%s</ReligionType>" %(gc.getReligionInfo(objUnitInfo.getReligionType()).getType()))
		else:
			szText = appendString(szText,"			<ReligionType>NONE</ReligionType>")

		if(objUnitInfo.getStateReligion() != -1):
			szText = appendString(szText,"			<StateReligion>%s</StateReligion>" %(gc.getReligionInfo(objUnitInfo.getStateReligion()).getType()))
		else:
			szText = appendString(szText,"			<StateReligion>NONE</StateReligion>")

		if(objUnitInfo.getPrereqReligion() != -1):
			szText = appendString(szText,"			<PrereqReligion>%s</PrereqReligion>" %(gc.getReligionInfo(objUnitInfo.getPrereqReligion()).getType()))
		else:
			szText = appendString(szText,"			<PrereqReligion>NONE</PrereqReligion>")

		if(objUnitInfo.getPrereqBuilding() != -1):
			szText = appendString(szText,"			<PrereqBuilding>%s</PrereqBuilding>" %(gc.getBuildingInfo(objUnitInfo.getPrereqBuilding()).getType()))
		else:
			szText = appendString(szText,"			<PrereqBuilding>NONE</PrereqBuilding>")

		if(objUnitInfo.getPrereqAndTech() != -1):
			szText = appendString(szText,"			<PrereqTech>%s</PrereqTech>" %(gc.getTechInfo(objUnitInfo.getPrereqAndTech()).getType()))
		else:
			szText = appendString(szText,"			<PrereqTech>NONE</PrereqTech>")
			
		if(self.isPrereqAndTechsDefined(iUnit)):
			szText = appendString(szText,"			<TechTypes>")
			for iI in range (gc.getDefineINT("NUM_UNIT_AND_TECH_PREREQS")):
				if(objUnitInfo.getPrereqAndTechs(iI) != TechTypes.NO_TECH):
					szText = appendString(szText,"				<PrereqTech>%s</PrereqTech>" %(gc.getTechInfo(objUnitInfo.getPrereqAndTechs(iI)).getType()))
			szText = appendString(szText,"			</TechTypes>")
		else:
			szText = appendString(szText,"			<TechTypes/>")
								
		if(objUnitInfo.getPrereqAndBonus() != -1):
			szText = appendString(szText,"			<BonusType>%s</BonusType>" %(gc.getBonusInfo(objUnitInfo.getPrereqAndBonus()).getType()))
		else:
			szText = appendString(szText,"			<BonusType>NONE</BonusType>")
		
		if(self.isPrereqOrBonusesDefined(iUnit)):
			szText = appendString(szText,"			<PrereqBonuses>")
			for iI in range (gc.getDefineINT("NUM_UNIT_PREREQ_OR_BONUSES")):
				if(objUnitInfo.getPrereqOrBonuses(iI) != BonusTypes.NO_BONUS):
					szText = appendString(szText,"				<BonusType>%s</BonusType>" %(gc.getBonusInfo(objUnitInfo.getPrereqOrBonuses(iI)).getType()))
			szText = appendString(szText,"			</PrereqBonuses>")
		else:
			szText = appendString(szText,"			<PrereqBonuses/>")

		if(self.isProductionTraitDefined(iUnit)):
			szText = appendString(szText,"			<ProductionTraits>")
			for iI in range (gc.getNumTraitInfos()):
				if(gc.getUnitInfo(iUnit).getProductionTraits(iI) > 0):
					szText = appendString(szText,"				<ProductionTrait>")
					szText = appendString(szText,"					<ProductionTraitType>%s</ProductionTraitType>" %(gc.getTraitInfo(iI).getType()))
					szText = appendString(szText,"					<iProductionTrait>%s</iProductionTrait>" %(gc.getUnitInfo(iUnit).getProductionTraits(iI)))
					szText = appendString(szText,"				</ProductionTrait>")
			szText = appendString(szText,"			</ProductionTraits>")
		else:
			szText = appendString(szText,"			<ProductionTraits/>")
			
		if(self.isFlavorsDefined(iUnit)):
			szText = appendString(szText,"			<Flavors>")
			for iI in range(gc.getNumFlavorTypes()):
				if(objUnitInfo.getFlavorValue(iI) != 0):
					szText = appendString(szText,"				<Flavor>")
					szText = appendString(szText,"					<FlavorType>%s</FlavorType>" %(gc.getFlavorTypes(iI)))
					szText = appendString(szText,"					<iFlavor>%s</iFlavor>" %(objUnitInfo.getFlavorValue(iI)))
					szText = appendString(szText,"				</Flavor>")
			szText = appendString(szText,"			</Flavors>")
		else:
			szText = appendString(szText,"			<Flavors/>")
			
		szText = appendString(szText,"			<iAIWeight>%s</iAIWeight>" %(objUnitInfo.getAIWeight()))
		szText = appendString(szText,"			<iCost>%s</iCost>" %(objUnitInfo.getProductionCost()))
		szText = appendString(szText,"			<iHurryCostModifier>%s</iHurryCostModifier>" %(objUnitInfo.getHurryCostModifier()))
		szText = appendString(szText,"			<iMinAreaSize>%s</iMinAreaSize>" %(objUnitInfo.getMinAreaSize()))
		szText = appendString(szText,"			<iMoves>%s</iMoves>" %(objUnitInfo.getMoves()))
		szText = appendString(szText,"			<iAirRange>%s</iAirRange>" %(objUnitInfo.getAirRange()))
		szText = appendString(szText,"			<iNukeRange>%s</iNukeRange>" %(objUnitInfo.getNukeRange()))
		szText = appendString(szText,"			<iWorkRate>%s</iWorkRate>" %(objUnitInfo.getWorkRate()))
		szText = appendString(szText,"			<iBaseDiscover>%s</iBaseDiscover>" %(objUnitInfo.getBaseDiscover()))
		szText = appendString(szText,"			<iDiscoverMultiplier>%s</iDiscoverMultiplier>" %(objUnitInfo.getDiscoverMultiplier()))
		szText = appendString(szText,"			<iBaseHurry>%s</iBaseHurry>" %(objUnitInfo.getBaseHurry()))
		szText = appendString(szText,"			<iHurryMultiplier>%s</iHurryMultiplier>" %(objUnitInfo.getHurryMultiplier()))
		szText = appendString(szText,"			<iBaseTrade>%s</iBaseTrade>" %(objUnitInfo.getBaseTrade()))
		szText = appendString(szText,"			<iTradeMultiplier>%s</iTradeMultiplier>" %(objUnitInfo.getTradeMultiplier()))
		szText = appendString(szText,"			<iGreatWorkCulture>%s</iGreatWorkCulture>" %(objUnitInfo.getGreatWorkCulture()))

		if(self.isTerrainImpassablesDefined(iUnit)):
			szText = appendString(szText,"			<TerrainImpassables>")
			for iI in range(gc.getNumTerrainInfos()):
				if(objUnitInfo.getTerrainImpassable(iI)):
					szText = appendString(szText,"				<TerrainImpassable>")
					szText = appendString(szText,"					<TerrainType>%s</TerrainType>" %(gc.getTerrainInfo(iI).getType()))
					szText = appendString(szText,"					<bTerrainImpassable>1</bTerrainImpassable>")
					szText = appendString(szText,"				</TerrainImpassable>")
				
			szText = appendString(szText,"			</TerrainImpassables>")
		else:
			szText = appendString(szText,"			<TerrainImpassables/>")

		if(self.isFeatureImpassablesDefined(iUnit)):
			szText = appendString(szText,"			<FeatureImpassables>")
			for iI in range(gc.getNumFeatureInfos()):
				if(objUnitInfo.getFeatureImpassable(iI)):
					szText = appendString(szText,"				<FeatureImpassable>")
					szText = appendString(szText,"					<FeatureType>%s</FeatureType>" %(gc.getFeatureInfo(iI).getType()))
					szText = appendString(szText,"					<bFeatureImpassable>1</bFeatureImpassable>")
					szText = appendString(szText,"				</FeatureImpassable>")
				
			szText = appendString(szText,"			</FeatureImpassables>")
		else:
			szText = appendString(szText,"			<FeatureImpassables/>")

		szText = appendString(szText,"			<iCombat>%s</iCombat>" %(objUnitInfo.getCombat()))
		szText = appendString(szText,"			<iAirCombat>%s</iAirCombat>" %(objUnitInfo.getAirCombat()))
		szText = appendString(szText,"			<iAirCombatLimit>%s</iAirCombatLimit>" %(objUnitInfo.getAirCombatLimit()))
		szText = appendString(szText,"			<iXPValueAttack>%s</iXPValueAttack>" %(objUnitInfo.getXPValueAttack()))
		szText = appendString(szText,"			<iXPValueDefense>%s</iXPValueDefense>" %(objUnitInfo.getXPValueDefense()))
		szText = appendString(szText,"			<iFirstStrikes>%s</iFirstStrikes>" %(objUnitInfo.getFirstStrikes()))
		szText = appendString(szText,"			<iChanceFirstStrikes>%s</iChanceFirstStrikes>" %(objUnitInfo.getChanceFirstStrikes()))
		szText = appendString(szText,"			<iInterceptionProbability>%s</iInterceptionProbability>" %(objUnitInfo.getInterceptionProbability()))
		szText = appendString(szText,"			<iEvasionProbability>%s</iEvasionProbability>" %(objUnitInfo.getEvasionProbability()))
		szText = appendString(szText,"			<iWithdrawalProb>%s</iWithdrawalProb>" %(objUnitInfo.getWithdrawalProbability()))
		szText = appendString(szText,"			<iCollateralDamage>%s</iCollateralDamage>" %(objUnitInfo.getCollateralDamage()))
		szText = appendString(szText,"			<iCollateralDamageLimit>%s</iCollateralDamageLimit>" %(objUnitInfo.getCollateralDamageLimit()))
		szText = appendString(szText,"			<iCollateralDamageMaxUnits>%s</iCollateralDamageMaxUnits>" %(objUnitInfo.getCollateralDamageMaxUnits()))
		szText = appendString(szText,"			<iCityAttack>%s</iCityAttack>" %(objUnitInfo.getCityAttackModifier()))
		szText = appendString(szText,"			<iCityDefense>%s</iCityDefense>" %(objUnitInfo.getCityDefenseModifier()))
		szText = appendString(szText,"			<iAnimalCombat>%s</iAnimalCombat>" %(objUnitInfo.getAnimalCombatModifier()))
		szText = appendString(szText,"			<iHillsAttack>%s</iHillsAttack>" %(objUnitInfo.getHillsAttackModifier()))
		szText = appendString(szText,"			<iHillsDefense>%s</iHillsDefense>" %(objUnitInfo.getHillsDefenseModifier()))

		if(self.isTerrainNativesDefined(iUnit)):
			szText = appendString(szText,"			<TerrainNatives>")
			for iI in range(gc.getNumTerrainInfos()):
				if(objUnitInfo.getTerrainNative(iI)):
					szText = appendString(szText,"				<TerrainNative>")
					szText = appendString(szText,"					<TerrainType>%s</TerrainType>" %(gc.getTerrainInfo(iI).getType()))
					szText = appendString(szText,"					<bTerrainNative>1</bTerrainNative>")
					szText = appendString(szText,"				</TerrainNative>")
				
			szText = appendString(szText,"			</TerrainNatives>")
		else:
			szText = appendString(szText,"			<TerrainNatives/>")
			
		if(self.isFeatureNativesDefined(iUnit)):
			szText = appendString(szText,"			<FeatureNatives>")
			for iI in range(gc.getNumFeatureInfos()):
				if(objUnitInfo.getFeatureNative(iI)):
					szText = appendString(szText,"				<FeatureNative>")
					szText = appendString(szText,"					<FeatureType>%s</FeatureType>" %(gc.getFeatureInfo(iI).getType()))
					szText = appendString(szText,"					<bFeatureNative>1</bFeatureNative>")
					szText = appendString(szText,"				</FeatureNative>")
				
			szText = appendString(szText,"			</FeatureNatives>")
		else:
			szText = appendString(szText,"			<FeatureNatives/>")

		if(self.isTerrainDefensesDefined(iUnit)):
			szText = appendString(szText,"			<TerrainDefenses>")
			for iI in range(gc.getNumTerrainInfos()):
				if(objUnitInfo.getTerrainDefenseModifier(iI) != 0):
					szText = appendString(szText,"				<TerrainDefense>")
					szText = appendString(szText,"					<TerrainType>%s</TerrainType>" %(gc.getTerrainInfo(iI).getType()))
					szText = appendString(szText,"					<iTerrainDefense>%s</iTerrainDefense>" %(objUnitInfo.getTerrainDefenseModifier(iI)))
					szText = appendString(szText,"				</TerrainDefense>")
				
			szText = appendString(szText,"			</TerrainDefenses>")
		else:
			szText = appendString(szText,"			<TerrainDefenses/>")
			
		if(self.isFeatureDefensesDefined(iUnit)):
			szText = appendString(szText,"			<FeatureDefenses>")
			for iI in range(gc.getNumFeatureInfos()):
				if(objUnitInfo.getFeatureDefenseModifier(iI) != 0):
					szText = appendString(szText,"				<FeatureDefense>")
					szText = appendString(szText,"					<FeatureType>%s</FeatureType>" %(gc.getFeatureInfo(iI).getType()))
					szText = appendString(szText,"					<iFeatureDefense>%s</iFeatureDefense>" %(objUnitInfo.getFeatureDefenseModifier(iI)))
					szText = appendString(szText,"				</FeatureDefense>")
				
			szText = appendString(szText,"			</FeatureDefenses>")
		else:
			szText = appendString(szText,"			<FeatureDefenses/>")

		if(self.isUnitClassAttackModifiersDefined(iUnit)):
			szText = appendString(szText,"			<UnitClassAttackMods>")
			for iI in range(gc.getNumUnitClassInfos()):
				if(objUnitInfo.getUnitClassAttackModifier(iI) != 0):
					szText = appendString(szText,"				<UnitClassAttackMod>")
					szText = appendString(szText,"					<UnitClassType>%s</UnitClassType>" %(gc.getUnitClassInfo(iI).getType()))
					szText = appendString(szText,"					<iUnitClassMod>%s</iUnitClassMod>" %(objUnitInfo.getUnitClassAttackModifier(iI)))
					szText = appendString(szText,"				</UnitClassAttackMod>")
				
			szText = appendString(szText,"			</UnitClassAttackMods>")
		else:
			szText = appendString(szText,"			<UnitClassAttackMods/>")
			
		if(self.isUnitClassDefenseModifiersDefined(iUnit)):
			szText = appendString(szText,"			<UnitClassDefenseMods>")
			for iI in range(gc.getNumUnitClassInfos()):
				if(objUnitInfo.getUnitClassDefenseModifier(iI) != 0):
					szText = appendString(szText,"				<UnitClassDefenseMod>")
					szText = appendString(szText,"					<UnitClassType>%s</UnitClassType>" %(gc.getUnitClassInfo(iI).getType()))
					szText = appendString(szText,"					<iUnitClassMod>%s</iUnitClassMod>" %(objUnitInfo.getUnitClassDefenseModifier(iI)))
					szText = appendString(szText,"				</UnitClassDefenseMod>")
				
			szText = appendString(szText,"			</UnitClassDefenseMods>")
		else:
			szText = appendString(szText,"			<UnitClassDefenseMods/>")
			
		if(self.isUnitCombatModifiersDefined(iUnit)):
			szText = appendString(szText,"			<UnitCombatMods>")
			for iI in range(gc.getNumUnitCombatInfos()):
				if(objUnitInfo.getUnitCombatModifier(iI) != 0):
					szText = appendString(szText,"				<UnitCombatMod>")
					szText = appendString(szText,"					<UnitCombatType>%s</UnitCombatType>" %(gc.getUnitCombatInfo(iI).getType()))
					szText = appendString(szText,"					<iUnitCombatMod>%s</iUnitCombatMod>" %(objUnitInfo.getUnitCombatModifier(iI)))
					szText = appendString(szText,"				</UnitCombatMod>")
				
			szText = appendString(szText,"			</UnitCombatMods>")
		else:
			szText = appendString(szText,"			<UnitCombatMods/>")

		if(self.isUnitCombatCollateralImmunesDefined(iUnit)):
			szText = appendString(szText,"			<UnitCombatCollateralImmunes>")
			for iI in range(gc.getNumUnitCombatInfos()):
				if(objUnitInfo.getUnitCombatCollateralImmune(iI) != 0):
					szText = appendString(szText,"				<UnitCombatCollateralImmune>")
					szText = appendString(szText,"					<UnitCombatType>%s</UnitCombatType>" %(gc.getUnitCombatInfo(iI).getType()))
					szText = appendString(szText,"					<iUnitCombatCollateralImmune>%s</iUnitCombatCollateralImmune>" %(objUnitInfo.getUnitCombatCollateralImmune(iI)))
					szText = appendString(szText,"				</UnitCombatCollateralImmune>")
				
			szText = appendString(szText,"			</UnitCombatCollateralImmunes>")
		else:
			szText = appendString(szText,"			<UnitCombatCollateralImmunes/>")
			
		if(self.isDomainModifiersDefined(iUnit)):
			szText = appendString(szText,"			<DomainMods>")
			for iI in range(DomainTypes.NUM_DOMAIN_TYPES):
				if(objUnitInfo.getDomainModifier(iI) != 0):
					szText = appendString(szText,"				<DomainMod>")
					szText = appendString(szText,"					<DomainType>%s</DomainType>" %(gc.getDomainInfo(iI).getType()))
					szText = appendString(szText,"					<iDomainMod>%s</iDomainMod>" %(objUnitInfo.getDomainModifier(iI)))
					szText = appendString(szText,"				</DomainMod>")
				
			szText = appendString(szText,"			</DomainMods>")
		else:
			szText = appendString(szText,"			<DomainMods/>")
			
		if(self.isBonusProductionModifiersDefined(iUnit)):
			szText = appendString(szText,"			<BonusProductionModifiers>")
			for iI in range(gc.getNumBonusInfos()):
				if(objUnitInfo.getBonusProductionModifier(iI) != 0):
					szText = appendString(szText,"				<BonusProductionModifier>")
					szText = appendString(szText,"					<BonusType>%s</BonusType>" %(gc.getBonusInfo(iI).getType()))
					szText = appendString(szText,"					<iProductonModifier>%s</iProductonModifier>" %(objUnitInfo.getBonusProductionModifier(iI)))
					szText = appendString(szText,"				</BonusProductionModifier>")
			szText = appendString(szText,"			</BonusProductionModifiers>")
		else:
			szText = appendString(szText,"			<BonusProductionModifiers/>")

		szText = appendString(szText,"			<iBombRate>%s</iBombRate>" %(objUnitInfo.getBombRate()))
		szText = appendString(szText,"			<iBombardRate>%s</iBombardRate>" %(objUnitInfo.getBombardRate()))

		if(objUnitInfo.getSpecialCargo() != -1):
			szText = appendString(szText,"			<SpecialCargo>%s</SpecialCargo>" %(gc.getSpecialUnitInfo(objUnitInfo.getSpecialCargo()).getType()))
		else:
			szText = appendString(szText,"			<SpecialCargo>NONE</SpecialCargo>")

		if(objUnitInfo.getDomainCargo() != -1):
			szText = appendString(szText,"			<DomainCargo>%s</DomainCargo>" %(gc.getDomainInfo(objUnitInfo.getDomainCargo()).getType()))
		else:
			szText = appendString(szText,"			<DomainCargo>NONE</DomainCargo>")

		szText = appendString(szText,"			<iCargo>%s</iCargo>" %(objUnitInfo.getCargoSpace()))
		szText = appendString(szText,"			<iConscription>%s</iConscription>" %(objUnitInfo.getConscriptionValue()))
		szText = appendString(szText,"			<iCultureGarrison>%s</iCultureGarrison>" %(objUnitInfo.getCultureGarrisonValue()))
		szText = appendString(szText,"			<iExtraCost>%s</iExtraCost>" %(objUnitInfo.getExtraCost()))
		szText = appendString(szText,"			<iAsset>%s</iAsset>" %(objUnitInfo.getAssetValue()))
		szText = appendString(szText,"			<iPower>%s</iPower>" %(objUnitInfo.getPowerValue()))
										
		szText = appendString(szText,"			<UnitMeshGroups>")
		szText = appendString(szText,"				<iGroupSize>%s</iGroupSize>" %(objUnitInfo.getGroupSize()))
		szText = appendString(szText,"				<fMaxSpeed>%s</fMaxSpeed>" %(objUnitInfo.getUnitMaxSpeed()))
		szText = appendString(szText,"				<iMeleeWaveSize>%s</iMeleeWaveSize>" %(objUnitInfo.getMeleeWaveSize()))
		szText = appendString(szText,"				<iRangedWaveSize>%s</iRangedWaveSize>" %(objUnitInfo.getRangedWaveSize()))

		for iK in range(objUnitInfo.getGroupDefinitions()):
			szText = appendString(szText,"				<UnitMeshGroup>")
			szText = appendString(szText,"					<iRequired>%s</iRequired>" %(objUnitInfo.getUnitGroupRequired(iK)))
			if(len(objUnitInfo.getEarlyArtDefineTag(iK)) > 0):
				szText = appendString(szText,"					<EarlyArtDefineTag>%s</EarlyArtDefineTag>" %(objUnitInfo.getEarlyArtDefineTag(iK)))
			if(len(objUnitInfo.getLateArtDefineTag(iK)) > 0):
				szText = appendString(szText,"					<LateArtDefineTag>%s</LateArtDefineTag>" %(objUnitInfo.getLateArtDefineTag(iK)))
			if(len(objUnitInfo.getMiddleArtDefineTag(iK)) > 0):
				szText = appendString(szText,"					<MiddleArtDefineTag>%s</MiddleArtDefineTag>" %(objUnitInfo.getMiddleArtDefineTag(iK)))
			szText = appendString(szText,"				</UnitMeshGroup>")
		
		szText = appendString(szText,"			</UnitMeshGroups>")

		szText = appendString(szText,"			<Button>%s</Button>" %(objUnitInfo.getButton()))
						
		if(len(objUnitInfo.getHotKey()) > 0):
			szText = appendString(szText,"			<HotKey>%s</HotKey>" %(objUnitInfo.getHotKey()))
		else:
			szText = appendString(szText,"			<HotKey/>")
		
		szText = appendString(szText,"			<bAltDown>%s</bAltDown>" %(boolToInt(objUnitInfo.isAltDown())))
		szText = appendString(szText,"			<bShiftDown>%s</bShiftDown>" %(boolToInt(objUnitInfo.isShiftDown())))
		szText = appendString(szText,"			<bCtrlDown>%s</bCtrlDown>" %(boolToInt(objUnitInfo.isCtrlDown())))
		szText = appendString(szText,"			<iHotKeyPriority>%s</iHotKeyPriority>" %(objUnitInfo.getHotKeyPriority()))

			
		if(self.isFreePromotionsDefined(iUnit)):
			szText = appendString(szText,"			<FreePromotions>")
			for iI in range(gc.getNumPromotionInfos()):
				if(objUnitInfo.getFreePromotions(iI)):
					szText = appendString(szText,"				<FreePromotion>")
					szText = appendString(szText,"					<PromotionType>%s</PromotionType>" %(gc.getPromotionInfo(iI).getType()))
					szText = appendString(szText,"					<bFreePromotion>1</bFreePromotion>")
					szText = appendString(szText,"				</FreePromotion>")
				
			szText = appendString(szText,"			</FreePromotions>")
		else:
			szText = appendString(szText,"			<FreePromotions/>")
			

		if(objUnitInfo.getLeaderPromotion() != -1):
			szText = appendString(szText,"			<LeaderPromotion>%s</LeaderPromotion>" %(gc.getPromotionInfo(objUnitInfo.getLeaderPromotion()).getType()))
		else:
			szText = appendString(szText,"			<LeaderPromotion>NONE</LeaderPromotion>")

		szText = appendString(szText,"			<iLeaderExperience>%s</iLeaderExperience>" %(objUnitInfo.getLeaderExperience()))
		
		if(objUnitInfo.getOrderPriority() != 5):
			szText = appendString(szText,"			<iOrderPriority>%s</iOrderPriority>" %(objUnitInfo.getOrderPriority()))

		szText = appendString(szText,"		</UnitInfo>")
			
		return szText

						
	def printUnits(self):	
	
		strSavePath = ""
		strFileSavePath = ""
		strModPath = ""
		strModAssetPath = ""
		strModAssetSavePath = ""
		strModAssetPath = ""
		
		if(os.access(CvPath.userActiveModDir,os.F_OK)):
			strModPath = CvPath.userActiveModDir
		elif(os.access(CvPath.installActiveModDir,os.F_OK)):
			strModPath = CvPath.installActiveModDir
		else:
			self.dataSavePopup(false)
			return
			
		strSavePath = "%s\%s" %(strModPath,g_strSaveDirectoryLocation)
		strModAssetPath = "%s\\Assets\\" %(strModPath)
		
		if(g_bCreateAssetHierarchy):
			strSavePath += "\Assets\XML\Units" 

		strFileSavePath = "%s\%s" %(strSavePath, "CIV4UnitInfos.xml")

		try:
			if(os.access(strSavePath,os.F_OK)):
				if(os.access(strFileSavePath,os.F_OK)):
					os.remove(strFileSavePath)
				os.removedirs(strSavePath)
		except:
			pass
			
		if(not os.access(strSavePath,os.F_OK)):
			os.makedirs(strSavePath)

							
		szText = "<?xml version=\"1.0\"?>"
		szText = appendString(szText,"<!-- Created by Tech Civilizeditor %s by TheLopez-->" %(editorVersion()))
		szText = appendString(szText,"<!-- Sid Meier's Civilization 4 -->")
		szText = appendString(szText,"<!-- Copyright Firaxis Games 2005 -->")
		szText = appendString(szText,"<!-- -->")
		szText = appendString(szText,"<!-- Unit Infos -->")
		szText = appendString(szText,"<Civ4UnitInfos xmlns=\"x-schema:CIV4UnitSchema.xml\">")
		szText = appendString(szText,"	<UnitInfos>")
				
		for iUnit in range(gc.getNumUnitInfos()):

			if(gc.getUnitInfo(iUnit).isDeleted()):
				continue

			szText = appendString(szText,self.printUnit(iUnit))
			
						
		szText = appendString(szText,"	</UnitInfos>")
		szText = appendString(szText,"</Civ4UnitInfos>")

			
		fd = os.open(strFileSavePath, os.O_CREAT)
		os.close(fd)

		fd = os.open(strFileSavePath, os.O_RDWR)
		os.write(fd, szText)
		os.close(fd)
		
		if(g_bSaveChangesInEditorAssetsDirectory):
			strModAssetPath = "%s\%s" %(strModPath,"\Assets\XML\Units")
			strModAssetSavePath = "%s\%s" %(strModPath, "\Assets\XML\Units\CIV4UnitInfos.xml")
			try:
				if(os.access(strModAssetPath,os.F_OK)):
					if(os.access(strModAssetSavePath,os.F_OK)):
						os.remove(strModAssetSavePath)
			except:
				pass
			
			if(not os.access(strModAssetPath,os.F_OK)):
				os.makedirs(strModAssetPath)

			fd = os.open(strModAssetSavePath, os.O_CREAT)
			os.close(fd)

			fd = os.open(strModAssetSavePath, os.O_RDWR)
			os.write(fd, szText)
			os.close(fd)
	

